/*
 * @Descripttion:
 * @Author: voanit
 * @Date: 2022-03-22 17:21:33
 * @LastEditors: voanit
 * @LastEditTime: 2022-03-22 18:33:25
 */
import axios from 'axios'
import { CHANNEL_GET, CHANNEL_ACTIVE, CHANNEL_NEWS } from '../actionTypes' // export const CHANNEL_GET = 'channel/get'
export const getChannel = () => {
  return async (dispatch) => {
    console.log(22)
    /* 发送异步请求 */
    const channels = await axios.get('http://geek.itheima.net/v1_0/channels')
    console.log(channels, 33)
    await dispatch({
      type: CHANNEL_GET,
      payload: channels.data.data.channels,
    })
  }
}

// export const getChannel = async (dispatch) => {
//   console.log(22)
//   /* 发送异步请求 */
//   const channels = await axios.get('http://geek.itheima.net/v1_0/channels')
//   console.log(channels, 33)
//   await dispatch({
//     type: CHANNEL_GET,
//     payload: channels.data.data.channels,
//   })
// }

//  dispatch(getChannel)

export const ChannelActive = (id) => {
  return async (dispatch) => {
    console.log(22)
    /* 发送异步请求 */
    // const res = await axios.get(
    //   `http://geek.itheima.net/v1_0/articles?channel_id=${id}&timestamp=${Date.now()}`
    // )
    // console.log(res, 678)

    await dispatch({
      type: CHANNEL_ACTIVE,
      payload: id,
    })
  }
}
